<!-- 组件说明 -->
<template>

  <div class='wrapper' ref="wrapper">
    <div class="content"> 
      <slot></slot>
    </div>
  </div>
</template>

<script>
  import BScroll from 'better-scroll'
  export default {
    name: "Scroll",
     props: {
      probeType: {
        type: Number,
        default: 0
      },
      pullUpLoad: {
        type: Boolean,
        default: false
      }
    },
    components: {

    },
   
    data () {
      return {
        bscroll: null
      };
    },
    computed: {

    },
    methods: {
      //先判断bscroll对象是否存在
       scrollTo(x, y, time=300) {
         this.bscroll && this.bscroll.scrollTo(x, y, time)
      },

      finishPullUp() {
         this.bscroll && this.bscroll.finishPullUp()
      },

      refresh() {
        this.bscroll && this.bscroll.refresh()
      }
    },
    mounted() {
      //默认情况下bscroll是不能实时监听滚动位置
        //probe侦测，0，1都是不侦测，2是手指滚动的过程中侦测，手指离开后的惯性滚动过程中不侦测，3只要是滚动都侦测
        this.bscroll = new BScroll(this.$refs.wrapper, {
          click: true,
          probeType: this.probeType,
          pullUpLoad: this.pullUpLoad
        });

        // 2.监听滚动的位置
        if(this.probeType == 2 || this.probeType == 3) {
          this.bscroll.on('scroll', (position) => {
            // console.log(position);
            this.$emit('scroll', position)
          })
        }


        //3.监听滚动到底部上拉加载
        if(this.pullUpLoad) {
          this.bscroll.on('pullingUp', () => {
            // console.log('上拉加载更多')
            this.$emit('pullingUp')
          })
        }
       

       
    }
  }
</script>

<style  scoped>
   
</style>